import java.util.HashSet;

public class LC0345 {
    public static String reverseVowels(String s) {
        if (s.isEmpty() || s.length() == 1) return s;

        int i = 0;
        int j = s.length() - 1;
        char[] charArray = s.toCharArray();
        HashSet<Character> vowels = new HashSet<>();
        vowels.add('a');
        vowels.add('e');
        vowels.add('i');
        vowels.add('o');
        vowels.add('u');
        vowels.add('A');
        vowels.add('E');
        vowels.add('I');
        vowels.add('O');
        vowels.add('U');

        while (i < j) {
            while (i < j && !vowels.contains(s.charAt(i))) i++;
            while (j > i && !vowels.contains(s.charAt(j))) j--;
            if (i < j && vowels.contains(s.charAt(i)) && vowels.contains(s.charAt(j))) {
                char tmp = charArray[i];
                charArray[i] = charArray[j];
                charArray[j] = tmp;
                i++;
                j--;
            }
        }

        return new String(charArray);
    }

    public static void main(String[] args) {
        String s = "leetcode";
        String reversed = reverseVowels(s);
        System.out.println(reversed);
    }
}
